//import {getxm,getxm1} from "api.js";
//import zzjg from "../../../../../themes/admin_default/xmgl/assets/utils/zzjg.js";
//import role from "../../../../../themes/admin_default/xmgl/assets/utils/role.js";
//import user from "../../../../../themes/admin_default/xmgl/assets/utils/userpublic.js";
//import { unixtimetostr } from "../../../../../themes/admin_default/xmgl/assets/utils/tools.js";

import { unixtimetostr } from "../utils/tools.js";
import tools from "../utils/tools.js";
import userservice, { getXsAndShqArr } from "../utils/userservice.js";
import xs from "../utils/xs.js";

axios.defaults.headers.post['Content-Type'] = 'application/json';

var Event = new Vue();//定义一个空的Vue实例 ，专门用来进行组件间通信

// 注册
Vue.component('xtest', {
    props: ['post'],
    template: '<h1>自定义组件!</h1>',
    data: function () {
        return {
            rootResourceTypeList: []
        };
    },
    mounted: function () {
        this.getRootResourceTypeList();
    },
    methods: {
    },
});

//挂载layer组件
Vue.use(LayerVue, {
    //此项设置置顶窗口的初始值，默认为100，一般无需配置，和其他组件冲突时可在此配置
    // 非置顶窗口请使用时单独设置
    zIndex: 100,
    //全局配置窗口皮肤
    skin: {
        //具体参数参见配置项：skin
    },
    //控制台打印相关信息
    log: true
});

const comp1 = {
    template: '#comp1',
    props: {
        t: { type: Number, required: false },//comp1组件用于判断是否用于了复用，组件对应数据表xs_khgz（客户工作），复用于 明天预约工作计划。
        d: { type: Object, required: false },//编辑数据时传入的数据
        i: { type: Number, required: false },//传入的index
    },
    data: function () {
        return {
            val: {
                XsAndShqArr: [],
                tsCascProps: {
                    multiple: true,        //多选开关
                    value: "id",
                    label: "user_nickname",
                    emitPath: false,
                },
            },
            form: {
                id: 0,           //重要，后台判断是新增还是更新数据的依据
                djbm: 0,        //单据编码
                zzjg_id: 0,      //组织机构id
                user_id: 0,      //用户id
                rz_date: '',    //日期

                type: 1, //当日工作
                khqdmc: '',//客户渠道名称
                khqy: '',//客户区域
                khjdr: '',//客户接待人
                khzw: '',//客户职务
                khdh: '',//客户电话
                jk_userid: [],//推送的人员id
                khgtnr: '',//客户沟通内容
                khxgjh: '',//下个计划
                khgtwt: '',//问题
            },
            rules: {
                //zzjgValue: [{type: 'array', required: true, message: '请选择所属机构', trigger:  'change' }],
                //roleValue: [{type: 'array', required: true, message: '请选择职务', trigger:  'change' }],
                //pass: [{ validator: validatePass, trigger: 'blur' }],
                //checkPass: [{ validator: validatePass2, trigger: 'blur' }],
            }
        }
    },
    mounted: function () {
        console.log('#comp1,mounted方法，窗口弹出，打印传入参数，type：', this.t, ",data:", this.d);
        if (Object.prototype.toString.call(this.d) === '[object Object]') {
            console.log("编辑模式,data:", this.d);
            this.form = this.d;
        }
        //
        userservice.getXsAndShqArr().then((res) => {
            console.log('userservice.getXsAndShqArr then:', res.data);
            this.val.XsAndShqArr = res.data;
        }).catch((res) => {
            console.log('userservice.getXsAndShqArr then:', res);
        })
    },
    watch: {
        /*t(val) {
            console.log("type变化:", val);
        },
        d: {
            //deep: true,
            immediate: true,
            handler: function (val) {
                console.log("data变化:", val);
            },
        },*/
    },
    methods: {
        changeTsCasc(e) {
            let that = this;
            //that.vs.xsName = this.$refs.xsCasc.getCheckedNodes()[0].pathLabels[0];   //取得label
            //that.searchData(that.form1.dateVal1,that.form1.xsid);
        },
        onCancel(form) {
        },
        onSubmit() {
            let that = this;
            console.log('传入的参数type', this.type);
            this.$refs.form.validate((valid) => {
                if (valid) {
                    console.log('表单数据验证通过,', that.form);

                    //自定义事件传给 空的Vue实例 ，专门用来进行组件间通信
                    if (that.t == 1) {
                        Event.$emit("comp1Close", that.form, that.i);//自定义事件  传递值“子向父组件传值”
                    } else if (that.t == 2) {
                        Event.$emit("comp4Close", that.form, that.i);//复用判断
                    }
                    Object.assign(this.$data, this.$options.data.call(this));   //本组件的数据重置

                } else {
                    console.log('表单数据验证有误');
                    return false;
                }
            });
        },
    },
};
const comp2 = {
    template: '#comp2',
    props: {
        t: { type: Number, required: true },//comp2组件用于判断是否用于了复用，组件对应数据表xs_qtgz（当日其它工作），复用于 明天其它工作时。
        d: { type: Object, required: false },//编辑数据时传入的数据
        i: { type: Number, required: true },//传入的index
    },
    data: function () {
        return {
            val: {
                XsAndShqArr: [],
                tsCascProps: {
                    multiple: true,        //多选开关
                    value: "id",
                    label: "user_nickname",
                    emitPath: false,
                },
            },
            form: {
                id: 0,           //重要，后台判断是新增还是更新数据的依据
                djbm: 0,    //单据编码
                zzjg_id: 0,      //组织机构id
                user_id: 0,      //用户id
                rz_date: '', //日期
                type: 1, //当日工作
                gznr: '',//工作内容
                tel: '',//联系电话
                jk_userid: [],//推送的人员id
                wcqk: '',//完成情况
                czwt: '',//存在问题
            },
        }
    },
    mounted: function () {
        console.log('窗口弹出，id：', this.layerid);
        console.log('comp2,t:', this.t, ',d:', this.d, ',i:', this.i);
        if (Object.prototype.toString.call(this.d) === '[object Object]') {
            console.log("编辑模式,data:", this.d);
            this.form = this.d;
        }
        userservice.getXsAndShqArr().then((res) => {
            console.log('userservice.getXsAndShqArr then:', res.data);
            this.val.XsAndShqArr = res.data;
        }).catch((res) => {
            console.log('userservice.getXsAndShqArr then:', res);
        })
    },
    methods: {
        changeTsCasc(e) {
            let that = this;
            //that.vs.xsName = this.$refs.xsCasc.getCheckedNodes()[0].pathLabels[0];   //取得label
            //that.searchData(that.form1.dateVal1,that.form1.xsid);
        },
        onCancel(form) {
        },
        onSubmit(form) {
            let that = this;
            console.log('传入的参数type：', this.t);
            this.$refs.form.validate((valid) => {
                if (valid) {
                    console.log('表单数据验证通过', that.form);

                    if (that.t == 1) {
                        Event.$emit("comp2Close", that.form, that.i);//自定义事件  传递值“子向父组件传值”
                    } else if (that.t == 2) {
                        Event.$emit("comp5Close", that.form, that.i);//复用判断
                    }
                    Object.assign(this.$data, this.$options.data.call(this));   //数据重置

                } else {
                    console.log('表单数据验证有误');
                    return false;
                }
            });
        },
    },
};
const comp3 = {
    template: '#comp3',
    props: {
        //strname: { type: String, required: true },        //调用组件时传入参数
        d: { type: Object, required: true, default: null },//编辑数据时传入的数据
        i: { type: Number, required: true, default: 0 },//传入的index
    },
    data: function () {
        return {
            val: {
                XsAndShqArr: [],
                tsCascProps: {
                    multiple: true,        //多选开关
                    value: "id",
                    label: "user_nickname",
                    emitPath: false,
                },
            },
            form: {
                id: 0,           //重要，后台判断是新增还是更新数据的依据
                djbm: 0,    //单据编码
                zzjg_id: 0,      //组织机构id
                user_id: 0,      //用户id
                rz_date: '', //日期
                type: 1, //当日工作
                gzwt: '',//工作问题
                tel: '',//电话
                jk_userid: [],//推送的人员id
                jjff: '',//解决方法
                xyzy: '',//需要资源
            },
        }
    },
    mounted: function () {
        console.log('comp3窗口弹出，id：', this.layerid);
        if (Object.prototype.toString.call(this.d) === '[object Object]') {
            console.log("编辑模式,data:", this.d);
            this.form = this.d;
        }
        userservice.getXsAndShqArr().then((res) => {
            console.log('userservice.getXsAndShqArr then:', res.data);
            this.val.XsAndShqArr = res.data;
        }).catch((res) => {
            console.log('userservice.getXsAndShqArr then:', res);
        })
    },
    methods: {
        changeTsCasc(e) {
            let that = this;
            //that.vs.xsName = this.$refs.xsCasc.getCheckedNodes()[0].pathLabels[0];   //取得label
            //that.searchData(that.form1.dateVal1,that.form1.xsid);
        },
        onCancel(form) {
        },
        onSubmit(form) {
            let that = this;
            this.$refs.form.validate((valid) => {
                if (valid) {
                    console.log('comp3表单数据验证通过', that.form);

                    //自定义事件传给 空的Vue实例 ，专门用来进行组件间通信
                    Event.$emit("comp3Close", that.form, that.i);//自定义事件  传递值“子向父组件传值”
                    Object.assign(this.$data, this.$options.data.call(this));   //数据重置
                } else {
                    console.log('comp3表单数据验证有误');
                    return false;
                }
            });
        },
    },
};

var vm = new Vue({
    el: '#app',
    components: {
        // 局部注册，标签名称comp1
        'comp1': comp1,
        'comp2': comp2,
        'comp3': comp3,
    },
    mounted: function () {
        // 访问组件的 DOM 元素
        //console.log(this.$el)
        let that = this;
        // 使用 $nextTick 方法访问父组件的数据
        this.$nextTick(() => {
            console.log('使用 $nextTick 方法访问父组件的数据', this.form)
            //console.log('unionid:', this.$refs.union_id.value);

            this.init_data();

            let td1;
            td1 = localStorage.getItem(that.tableData1StorageName);
            console.log("localStorage.getItem('tableData1')，td1:", td1);
            if (td1 == undefined || td1 == 'undefined' || td1 == null) {
                this.tableData1 = [];
            } else {
                this.tableData1 = JSON.parse(td1);
            }

            let td2;
            td2 = localStorage.getItem(that.tableData2StorageName);
            if (td2 == undefined || td2 == 'undefined' || td2 == null) {
                this.tableData2 = [];
            } else {
                this.tableData2 = JSON.parse(td2);
            }

            let td3;
            td3 = localStorage.getItem(that.tableData3StorageName);
            if (td3 == undefined || td3 == 'undefined' || td3 == null) {
                this.tableData3 = [];
            } else {
                this.tableData3 = JSON.parse(td3);
            }

            let td4;
            td4 = localStorage.getItem(that.tableData4StorageName);
            if (td4 == undefined || td4 == 'undefined' || td4 == null) {
                this.tableData4 = [];
            } else {
                this.tableData4 = JSON.parse(td4);
            }

            let td5;
            td5 = localStorage.getItem(that.tableData5StorageName);
            if (td5 == undefined || td5 == 'undefined' || td5 == null) {
                this.tableData5 = [];
            } else {
                this.tableData5 = JSON.parse(td5);
            }

        })
        // 监听数据变化
        this.$watch('data', () => {
            console.log('data changed');
        })
        // 在组件销毁时取消异步操作
        this.$once('hook:beforeDestroy', () => {
            that.cancelAsyncTask();
        })

        //响应子组件1事件
        Event.$on('comp1Close', (form, index) => {
            //this.name = name;//箭头函数内部不会产生新的this，这边如果不用=>,this指代Event

            let td = this.tableData1;
            if (td == undefined || td == 'undefined' || td == null) td = [];

            console.log('comp1Close 子组件事件传值过来,index:', index, ",form:", form);
            if (index > 0) {
                td[index] = form;
            } else {
                td.push(form);
            }
            localStorage.setItem(that.tableData1StorageName, JSON.stringify(td));

            this.tableData1 = td;

            this.$layer.close(this.layer1.id);
        })

        Event.$on('comp2Close', (form, index) => {
            //this.name = name;//箭头函数内部不会产生新的this，这边如果不用=>,this指代Event
            let td = this.tableData2;
            if (td == undefined || td == 'undefined' || td == null) td = [];

            console.log('comp2Close 子组件事件传值过来,index:', index, ",form:", form);
            if (index > 0) {
                td[index] = form;
            } else {
                td.push(form);
            }
            localStorage.setItem(that.tableData2StorageName, JSON.stringify(td));

            this.tableData2 = td;

            that.$layer.close(this.layer2.id);
        })

        Event.$on('comp3Close', (form, index) => {
            //this.name = name;//箭头函数内部不会产生新的this，这边如果不用=>,this指代Event
            let td = this.tableData3;
            if (td == undefined || td == 'undefined' || td == null) td = [];

            console.log('comp3Close 子组件事件传值过来,index:', index, ",form:", form);
            if (index > 0) {
                td[index] = form;
            } else {
                td.push(form);
            }
            localStorage.setItem(that.tableData3StorageName, JSON.stringify(td));

            this.tableData3 = td;

            that.$layer.close(this.layer3.id);
        })

        Event.$on('comp4Close', (form, index) => {
            //this.name = name;//箭头函数内部不会产生新的this，这边如果不用=>,this指代Event
            let td = this.tableData4;
            if (td == undefined || td == 'undefined' || td == null) td = [];

            console.log('comp4Close 子组件事件传值过来,index:', index, ",form:", form);
            if (index > 0) {
                td[index] = form;
            } else {
                td.push(form);
            }
            localStorage.setItem(that.tableData4StorageName, JSON.stringify(td));

            this.tableData4 = td;
            that.$layer.close(this.layer4.id);
        })

        Event.$on('comp5Close', (form, index) => {
            //this.name = name;//箭头函数内部不会产生新的this，这边如果不用=>,this指代Event
            let td = this.tableData5;
            if (td == undefined || td == 'undefined' || td == null) td = [];

            console.log('comp5Close 子组件事件传值过来,index:', index, ",form:", form);
            if (index > 0) {
                td[index] = form;
            } else {
                td.push(form);
            }
            localStorage.setItem(that.tableData5StorageName, JSON.stringify(td));

            this.tableData5 = td;
            that.$layer.close(this.layer5.id);
        })
    },
    data: function () {
        return {
            columnWidth: '90px',    //表格控制列宽度

            iserror: false,      //如果接口有错误，置true，不允许提交

            userInfo: {},                               //用户信息
            todaystr: tools.dateformat(Date()),         //标题显示日期

            form: {
                id: 0,
                djbm: 0,//单据编码，自动生成
                dj_date: '',//单据日期，自动生成
                user_id: 0,//创建用户id
                comp1: {},
                comp2: {},
                comp3: {},
            },

            layer1: new Object({
                id: 'comp1', title: '新增客户沟通工作',
                component: 'comp1', //弹层弹出的组件名称
                type: 1 //组件里的type字段，type-1表示是今天的工作，type-2表示是明天的工作。用于组件复用时的问题
            }),  //弹出窗口1：comp1，id即打开弹出层后的layerid号
            layer2: new Object({ id: 'comp1', title: '新增其它工作', component: 'comp2', type: 1 }),
            layer3: new Object({ id: 'comp1', title: '新增客户沟通工作', component: 'comp3', type: 1 }),
            layer4: new Object({ id: 'comp1', title: '新增明天预约', component: 'comp1', type: 2 }),
            layer5: new Object({ id: 'comp1', title: '新增明天其它工作', component: 'comp2', type: 2 }),

            tableData1: [], tableData1StorageName: '',
            tableData2: [], tableData2StorageName: '',
            tableData3: [], tableData3StorageName: '',
            tableData4: [], tableData4StorageName: '',
            tableData5: [], tableData5StorageName: '',
        }
    },
    methods: {
        unixtimetostr,
        add(layerObj, params) {
            let that = this;
            layerObj.id = that.$layer.open({
                id: layerObj.id,   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: layerObj.title,
                content: {
                    component: layerObj.component,      //打开的组件名称
                    data: { type: 1 },       //传给子组件的参数,{a:'a"}
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },

        add1() {
            let that = this;
            //this.$layer.confirm();//挂载layer组件
            that.layer1.id = that.$layer.open({
                id: 'comp1layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '新增今日客户沟通工作',
                content: {
                    component: comp1,      //打开的组件名称
                    data: { t: 1, d: null, i: 0 },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp1edit(i, e) {
            console.log("comp1edit", e[i]);

            let that = this;
            //this.$layer.confirm();//挂载layer组件
            that.layer1.id = that.$layer.open({
                id: 'comp1layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '编辑今日客户沟通工作',
                content: {
                    component: comp1,      //打开的组件名称
                    data: { t: 1, d: e[i], i: i },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp1del(i, e) {
            let that = this;
            console.log('comp1del index:', i, ',row', e);

            let row = e[i];
            if (row['id']) xs.deletekhgz({ id: row['id'] })
                .then((res) => {
                    e.splice(i, 1);
                    localStorage.setItem(that.tableData1StorageName, JSON.stringify(e));

                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除成功!',
                        type: 'success',
                        center: true
                    });
                })
                .catch((res => {
                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除失败!',
                        type: 'error',
                        center: true
                    });
                }));
        },
        //没有使用，弹层关闭回调函数
        comp1OnClose(dom, index, id) {
            let that = this;
            console.log('弹层窗口关闭，cancel回调， onclose,dom:', dom, ',index:', index, ',id:', id);
            //that.tableData1.push(row);
        },

        add2() {
            let that = this;
            //this.$layer.confirm();//挂载layer组件
            that.layer2.id = that.$layer.open({
                id: 'comp2layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '新增当日其它工作',
                content: {
                    component: comp2,      //打开的组件名称
                    data: { t: 1, d: undefined, i: 0 },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp2edit(i, e) {
            console.log("comp2edit", e);
            let that = this;
            //this.$layer.confirm();//挂载layer组件
            that.layer2.id = that.$layer.open({
                id: 'comp2layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '编辑当日其它工作',
                content: {
                    component: comp2,      //打开的组件名称
                    data: { t: 1, d: e[i], i: i },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp2del(i, e) {
            let that = this;
            console.log('comp2del index:', i, ',row', e);

            let row = e[i];
            if (row['id']) xs.deleteqtgz({ id: row['id'] })
                .then((res) => {
                    e.splice(i, 1);
                    localStorage.setItem(that.tableData2StorageName, JSON.stringify(e));

                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除成功!',
                        type: 'success',
                        center: true
                    });
                })
                .catch((res => {
                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除失败!',
                        type: 'error',
                        center: true
                    });
                }));
        },

        add3() {
            let that = this;
            that.layer3.id = that.$layer.open({
                id: 'comp3layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '新增当日工作问题',
                content: {
                    component: comp3,      //打开的组件名称
                    data: { t: 1, d: null, i: 0 },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp3edit(i, e) {
            console.log("comp3edit", e);
            let that = this;
            that.layer3.id = that.$layer.open({
                id: 'comp3layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '编辑当日工作问题',
                content: {
                    component: comp3,      //打开的组件名称
                    data: { t: 1, d: e[i], i: i },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp3del(i, e) {
            let that = this;
            console.log('comp3del index:', i, ',row', e);

            let row = e[i];
            if (row['id']) xs.deletegzwt({ id: row['id'] })
                .then((res) => {
                    e.splice(i, 1);
                    localStorage.setItem(that.tableData3StorageName, JSON.stringify(e));

                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除成功!',
                        type: 'success',
                        center: true
                    });
                })
                .catch((res => {
                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除失败!',
                        type: 'error',
                        center: true
                    });
                }));
        },

        add4() {
            let that = this;
            that.layer4.id = that.$layer.open({
                id: 'comp4layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '新增当日其它工作',
                content: {
                    component: comp1,      //打开的组件名称
                    data: { t: 2, d: null, i: 0 },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp4edit(i, e) {
            console.log("comp4edit", e);
            let that = this;
            that.layer4.id = that.$layer.open({
                id: 'comp4layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '编辑当日其它工作',
                content: {
                    component: comp1,      //打开的组件名称
                    data: { t: 2, d: e[i], i: i },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp4del(i, e) {
            let that = this;
            console.log('comp4del index:', i, ',row', e);

            let row = e[i];
            if (row['id']) xs.deletekhgz({ id: row['id'] })
                .then((res) => {
                    e.splice(i, 1);
                    localStorage.setItem(that.tableData4StorageName, JSON.stringify(e));

                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除成功!',
                        type: 'success',
                        center: true
                    });
                })
                .catch((res => {
                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除失败!',
                        type: 'error',
                        center: true
                    });
                }));
        },

        add5() {
            let that = this;
            that.layer5.id = that.$layer.open({
                id: 'comp5layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '新增当日其它工作',
                content: {
                    component: comp2,      //打开的组件名称
                    data: { t: 2, d: null, i: 0 },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp5edit(i, e) {
            console.log("comp5edit", e);
            let that = this;
            that.layer5.id = that.$layer.open({
                id: 'comp5layer',   //设置该值后，不管内容区是什么类型，都只允许同时弹出一个
                title: '编辑当日其它工作',
                content: {
                    component: comp2,      //打开的组件名称
                    data: { t: 2, d: e[i], i: i },       //传给子组件的参数
                },
                minArea: ['600px', '600px'],    //最小尺寸，宽高
                //maxArea :['200px', '200px'],  //最大尺寸，宽高
                setTop: true,      //置顶
                isMax: false,   //默认最大化
                shade: [0.8, '#393D49'],
                closeBtn: true,
                destroyOnClose: true,       //关闭后销毁窗口
                //cancel : that.comp1OnClose,     //关闭时的回调
            }); //等价于 this.$layer({*配置项*})
        },
        comp5del(i, e) {
            let that = this;
            console.log('comp5del,index:', i, ",row:", e[i]);

            let row = e[i];
            if (row['id']) xs.deleteqtgz({ id: row['id'] })
                .then((res) => {
                    e.splice(i, 1);
                    localStorage.setItem(that.tableData5StorageName, JSON.stringify(e));

                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除成功!',
                        type: 'success',
                        center: true
                    });
                })
                .catch((res => {
                    console.log(res);
                    that.$message({
                        showClose: true,
                        message: '删除失败!',
                        type: 'error',
                        center: true
                    });
                }));
        },

        changeZzjgCasc(e) {
            console.log("选中的值:", e)
            this.$nextTick(() => {
                // 级联多选专业 的最后一项的数组
                let newArr = []
                this.form.zzjgValue.map((item) => {
                    newArr.push(item[item.length - 1])
                })
                this.form.zzjgValue = newArr;
                console.log('转换后的zzjgValue：', newArr);
            });
        },
        onSubmit(f) {
            let that = this;
            console.log("提交：this.form:", this.form);
            /*
                        if (that.iserror) {
                            that.$message({
                                showClose: true,
                                message: '页面初始化时有错误，刷新页面后再试',
                                type: 'error',
                                center: true
                            });
                            return;
                        }
            */
            if (that.form.djbm > 0) {
                //更新数据
            } else {
                //新增数据
                //生成djbm:0,//单据编码，自动生成
                let r = tools.randomInt1ToN(1024);
                that.form.djbm = tools.unixtimestamp() + r;
                //生成dj_date:'',//单据日期，自动生成
                that.form.dj_date = tools.todaystr();
            }
            that.form.user_id = that.userInfo.id;//创建用户id

            //读取存储内容
            that.form.comp1 = this.tableData1;
            that.form.comp2 = this.tableData2;
            that.form.comp3 = this.tableData3;
            that.form.comp4 = this.tableData4;
            that.form.comp5 = this.tableData5;

            console.log('提交表单数据：', that.form);

            //this.$refs.form.validate((valid) => {     //验证表单
            xs.savexsgz(that.form)
                .then((res) => {
                    console.log('提交表单返回', res);
                    //成功
                    that.$message({
                        showClose: true,
                        message: '保存成功!',
                        type: 'success',
                        center: true
                    });
                    //保存成功清空所有本地缓存
                    localStorage.removeItem(that.tableData1StorageName);
                    localStorage.removeItem(that.tableData2StorageName);
                    localStorage.removeItem(that.tableData3StorageName);
                    localStorage.removeItem(that.tableData4StorageName);
                    localStorage.removeItem(that.tableData5StorageName);
                    //关闭页面
                    window.close();
                    //location.replace("/admin");
                })
                .catch((res) => {
                    console.log('提交表单返回错误', res);
                    that.$message({
                        showClose: true,
                        message: res.msg,
                        type: 'error',
                        center: true
                    });
                });
        },
        onCancel(form) {
            location.assign("/");
        },
        resetForm(form) {
            this.$refs[form].resetFields();
        },
        backurl() {
            window.history.back();  //返回上一页
        },
    },
});

vm.init_data = function () {
    let that = this;
    userservice.getLoginUserInfo()
        .then((res) => {
            console.log("userservice success:", res);
            that.userInfo = res.data;
            let zzjgList = res.data.zzjg;
            let zzjgmcArr = zzjgList.map(v => {
                return v.zzjg_mc;
            });
            that.userInfo.zzjgmc = zzjgmcArr.join(',');

            that.tableData1StorageName = 'tableDate1_' + res.data.id;
            that.tableData2StorageName = 'tableDate2_' + res.data.id;
            that.tableData3StorageName = 'tableDate3_' + res.data.id;
            that.tableData4StorageName = 'tableDate4_' + res.data.id;
            that.tableData5StorageName = 'tableDate5_' + res.data.id;
        }).then(() => {
            xs.indexxsgz()
                .then((res) => {
                    console.log('xs.readtoday success:', res.data);
                    that.iserror = false;
                    if (res.data == undefined || res.data == 'undefined' || res.data == null || res.data == '') {
                        return;
                    } else {
                        that.form = res.data;
                    }

                    if (res.data.comp1 == undefined || res.data.comp1 == 'undefined' || res.data.comp1 == null) {

                    } else {
                        //将以逗号分割的jk_userid转换成数组
                        //console.log("res.data.comp1:", res.data.comp1);
                        let comp1 = res.data.comp1;
                        for (let i = 0; i < comp1.length; i++) {
                            let v = comp1[i].jk_userid;
                            v = v.split(',');
                            res.data.comp1[i].jk_userid = v;
                        }
                        //console.log("res.data.comp1:", res.data.comp1);

                        that.tableData1 = res.data.comp1;
                        localStorage.setItem(that.tableData1StorageName, JSON.stringify(that.tableData1));
                    }

                    if (res.data.comp2 == undefined || res.data.comp2 == 'undefined' || res.data.comp2 == null) {

                    } else {
                        //将以逗号分割的jk_userid转换成数组
                        //console.log("res.data.comp2:", res.data.comp2);
                        let comp2 = res.data.comp2;
                        for (let i = 0; i < comp2.length; i++) {
                            let v = comp2[i].jk_userid;
                            v = v.split(',');
                            res.data.comp2[i].jk_userid = v;
                        }
                        //console.log("res.data.comp2:", res.data.comp2);

                        that.tableData2 = res.data.comp2;
                        localStorage.setItem(that.tableData2StorageName, JSON.stringify(that.tableData2));
                    }

                    if (res.data.comp3 == undefined || res.data.comp3 == 'undefined' || res.data.comp3 == null) {

                    } else {
                        //将以逗号分割的jk_userid转换成数组
                        //console.log("res.data.comp3:", res.data.comp3);
                        let comp3 = res.data.comp3;
                        for (let i = 0; i < comp3.length; i++) {
                            let v = comp3[i].jk_userid;
                            v = v.split(',');
                            res.data.comp3[i].jk_userid = v;
                        }
                        //console.log("res.data.comp3:", res.data.comp3);

                        that.tableData3 = res.data.comp3;
                        localStorage.setItem(that.tableData3StorageName, JSON.stringify(that.tableData3));
                    }

                    if (res.data.comp4 == undefined || res.data.comp4 == 'undefined' || res.data.comp4 == null) {

                    } else {
                        //将以逗号分割的jk_userid转换成数组
                        //console.log("res.data.comp4:", res.data.comp4);
                        let comp4 = res.data.comp4;
                        for (let i = 0; i < comp4.length; i++) {
                            let v = comp4[i].jk_userid;
                            v = v.split(',');
                            res.data.comp4[i].jk_userid = v;
                        }
                        //console.log("res.data.comp4:", res.data.comp4);

                        that.tableData4 = res.data.comp4;
                        localStorage.setItem(that.tableData4StorageName, JSON.stringify(that.tableData4));
                    }

                    if (res.data.comp5 == undefined || res.data.comp5 == 'undefined' || res.data.comp5 == null) {

                    } else {
                        //将以逗号分割的jk_userid转换成数组
                        //console.log("res.data.comp5:", res.data.comp5);
                        let comp5 = res.data.comp5;
                        for (let i = 0; i < comp5.length; i++) {
                            let v = comp5[i].jk_userid;
                            v = v.split(',');
                            res.data.comp5[i].jk_userid = v;
                        }
                        //console.log("res.data.comp5:", res.data.comp5);

                        that.tableData5 = res.data.comp5;
                        localStorage.setItem(that.tableData5StorageName, JSON.stringify(that.tableData5));
                    }
                })
                .catch((res) => {
                    console.log('xs.readtoday err:', res);
                    that.iserror = true;
                });
        })
        .catch(res => {
            console.log("userservice err:", res);
        });


}


